Public Class Tools
    Public Shared Sub CopyObject(ByVal ObjectType As Type, _
        ByVal ExistingInstance As Object, _
        ByRef NewInstance As Object)

        Dim Props() As Reflection.PropertyInfo = _
            ObjectType.GetProperties(Reflection.BindingFlags.Public Or _
            Reflection.BindingFlags.Instance)

        For Each PropItem As Reflection.PropertyInfo In Props
            If PropItem.CanWrite Then
                PropItem.SetValue(NewInstance, _
                PropItem.GetValue(ExistingInstance, Nothing), Nothing)
            End If
        Next

    End Sub

    Public Shared Function EnumFromString(Of T)(ByVal what As String) As T
        Try
            Return CType(System.Enum.Parse(GetType(T), what, True), T)
        Catch ex As Exception
            Dim values As Array = System.Enum.GetValues(GetType(T))
            Return CType(values.GetValue(0), T)
        End Try
    End Function

End Class
